# include<bits/stdc++.h>
using namespace std;

typedef long long ll;


int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> arr1(n), arr2(m);
  for (int i = 0; i < n; ++i)
  {
    cin >> arr1[i];
  }
  for (int i = 0; i < m; ++i)
  {
    cin >> arr2[i];
  }

  ll ans = 0;
  int i = 0, j = 0;
  while (i < n && j < m)
  {
    if (arr1[i] == arr2[j])
    {
      ++i, ++j;
    }
    else if (arr1[i] < arr2[j])
    {
      ++i, ++ans;
      arr1[i] += arr1[i - 1];
    }
    else 
    {
      ++j, ++ans;
      arr2[j] += arr2[j - 1];
    }
  }
  cout << ans;
  return 0;
}
